<html>
<body>
<script language=JavaScript>
function closeIt() {
close();
}
</script>
<?php
require("../config.php");

if($_SESSION['login'] != "" && $_SESSION['pass'] != ""){
  $login = $_SESSION['login'];
  $name = $_POST['name'];
  $uploaddir = 'photos/'; // Relative path under webroot
  $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
  if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    $photo = $uploadfile;  
    $query = "INSERT INTO photos VALUES('$login','$name','$photo')";
    $result = mysql_query($query);
    //echo "Your photo saved. <form><input onclick=closeIt() type=button value=Close></form>";    
    echo "Your photo saved. <a href=index.php>Back</a>";
  }else{
    echo "File uploading failed. <a href=index.php>Back</a>\n";
  };

  mysql_close();
};
?>
</body>
</html>
